package com.odais.DataManagement;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;

import android.content.Context;
import android.os.AsyncTask;
import android.widget.Toast;

import com.odais.Reservation.Reservation;
import com.odais.Reservation.ReservationList;
import com.odais.UserManagement.UserManager;
import com.odais.json.JSON_IO_Interface;

/**
 * 
 * @author LDC
 * 
 * Data manager will handle all communication. That means, it will fetch data on server if online
 * or in the SQLite if offline.
 * In addition, it will be able to sync both DB.
 * 
 * Each communication will be initiated as an async task.
 * 
 * Every data sets must be static...
 *
 */

public class DataManager
{
// ===========================================================
// Constants
// ===========================================================
	public static final int RESERVATION_STATUS_PENDING = 1000;
	public static final int RESERVATION_STATUS_CONFIRMED = 2000;

	public static final String UPDATE_TYPE_FULL_LIST = "FULL_LIST";
	public static final String UPDATE_TYPE_PENDING_LIST = "PENDING_LIST";
	public static final String UPDATE_TYPE_CONFIRMED_LIST = "CONFIRMED_LIST";
	public static final String UPDATE_TYPE_CONFIRMED_DATED_LIST = "CONFIRMED_DATED_LIST";

// ===========================================================
// Fields
// ===========================================================
	private static ArrayList<DataListener> listeners = new ArrayList<DataListener> ();
	
	private Context mContext;
	private ReservationList reservationList =  new ReservationList();
	private ReservationList roomReservationList = new ReservationList();

// ===========================================================
// Constructors
// ===========================================================

	public DataManager(Context mContext) {
		super();
		this.mContext = mContext;
		
	}

// ===========================================================
// Getter & Setter
// ===========================================================


// ===========================================================
// Methods for/from SuperClass/Interfaces
// ===========================================================
	
	public static void setOnDataUpdateListener (DataListener listener) 
    {
        // Store the listener object
        listeners.add(listener);
    }

	public void UpdateReservationList()
	{
		//new GetReservationListOnServer(mContext, reservationList, listeners).execute();
		new GetReservationListOnSQLite(mContext, reservationList, listeners).execute();

	}

	public void UpdateReservationList(String Type)
	{
		//new GetReservationListOnServer(mContext, reservationList, listeners).execute();
		new GetReservationListOnSQLite(mContext, roomReservationList, listeners, Type, "").execute();

	}

	public void GetRoomAt(String timestamp)
	{
		//Get all confirmed reservation with attributed table, at a specified date
		new GetReservationListOnSQLite(mContext, roomReservationList, listeners, DataBaseHelper.COLUMN_TIMESTAMP, timestamp).execute();
		
	}

	public void updateItem(Reservation reservation)
	{
		new UpdateReservationOnSQLite(mContext, reservation).execute();
	}


}